package com.tencent.yumeko;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer")
public class ConsumerRouterController {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProducerRouterService producerRouterService;

    /**
     * Get info of two value.
     *
     * @return info
     */
    @GetMapping("/feign")
    public String feign(@RequestParam String name) {
        User user = new User();
        user.setName(name);
        user.setAge(18);
        return producerRouterService.info(name, user);
    }

    /**
     * Get information of callee.
     *
     * @return information of callee
     */
    @GetMapping("/rest")
    public String rest(@RequestParam String name) {
        User user = new User();
        user.setName(name);
        user.setAge(18);
        return restTemplate.postForObject(
                "http://RouterProducerService/producer/info?name={name}", user, String.class, name);
    }

    /**
     * health check.
     *
     * @return health check info
     */
    @GetMapping("/healthCheck")
    public String healthCheck() {
        return "pk ok";
    }
}
